package leetcode.editor.cn.q1xx

import leetcode.editor.cn.ListNode

class Q160 {
    fun getIntersectionNode(headA: ListNode?, headB: ListNode?): ListNode? {
        if (headA == null || headB == null) return null
        var nodeA: ListNode? = headA
        var nodeB: ListNode? = headB

        while (nodeA != nodeB ) {
            nodeA = if (nodeA!=null) nodeA.next else headB
            nodeB = if (nodeB!=null) nodeB.next else headA
        }
        return nodeA
    }
}